# -*- coding: UTF-8 -*-
import os
import os.path
import sys
current_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(current_dir)
sys.path.append("..")

import genYAML
import case
import time
import ruamel.yaml as yaml
import re
from file_method import Location_Sample
# setting loading
def Generate_Small(temp_dic,store_path):
    local_time = time.asctime(time.localtime(time.time()))  # 当前时间
    format_time = time.strftime("%Y-%m-%d_%H_%M_%S")
    author_name=temp_dic['description']['author']
    history=''
    model=''
    name=temp_dic['description']['name']
    purpose=temp_dic['description']['purpose']
    #TODO   减少耦合！
    # genyaml_path = Location_Sample.win_to_ubuntu_filepath("Src_Code\\Tmp-django\\yaml_f\\%s_%s_%s.yaml"%('-'.join(format_time.split()),'-'.join(author_name.split()),'-'.join(name.split())), "Src_Code")

    genyaml_path = (store_path+"/%s_%s_%s.yaml"%('-'.join(format_time.split()),'-'.join(author_name.split()),'-'.join(name.split())))
    # genyaml_path=("."+"/%s_%s_%s.yaml"%('-'.join(format_time.split()),'-'.join(author_name.split()),'-'.join(name.split())))
    file_path=Location_Sample.win_to_ubuntu_filepath(temp_dic['bundle']['file_path'],"Sample")
    # file_path=temp_dic['bundle']['file_path']
    # xml_path=Location_Sample.win_to_ubuntu_filepath(temp_dic['bundle']['xml_path'],"Sample")


    BundleSetup=temp_dic['bundle']['start']
    BundleTearoff=temp_dic['bundle']['end']
    #正样本和负样本匹配模式
    match_pa=temp_dic['description']['match_pattern']
    #搜索模式
    flag=temp_dic['description']['search_pattern']
    #设置info和des
    search_path=file_path
    temp_case=case.case()
    list(map(temp_case.setDescriptionAttribute,[temp_case.time_str,temp_case.author_str,temp_case.history_str,temp_case.name_str,temp_case.purpose_str,temp_case.match_str,
                                                temp_case.search_mode_str,temp_case.search_path_str,temp_case],
        [local_time,author_name,history,name,purpose,match_pa,flag,search_path]))
    temp_case.setInformationAttribute(temp_case.model_str,model)
    #多命令
    cmd=re.compile(r'(set --.*?)/')
    bundle_start=cmd.findall(BundleSetup)
    bundle_end=cmd.findall(BundleTearoff)
    temp_case.newBundle()
    temp_case.addBundleSetup(bundle_start)
    temp_case.addBundleTearoff(bundle_end)

    genYAML.genCaseYaml(genyaml_path, file_path,temp_case,flag)
    return genyaml_path  #返回产生的文件路径




